package com.bit.demo.springbookdemo.mapper;

import com.bit.demo.springbookdemo.model.BookInfo;
import com.bit.demo.springbookdemo.model.PageRequest;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface BookMapper {
    /**
     * 新增一本书
     * @param bookInfo
     * @return 影响的行数
     */
    @Insert("insert into book_info(book_name,author,count,price,publish) values" +
            "(#{bookName},#{author},#{count},#{price},#{publish})")
    Integer addBook(BookInfo bookInfo);

    @Select("select * from book_info where status!=0 limit #{offset},#{pageSize} ")
    List<BookInfo> getListByPage(PageRequest pageRequest);

    @Select("select count(1) from book_info where status!=0")
    Integer count();

    @Select("select * from book_info where status!=0 and id=#{bookId}")
    BookInfo queryBookById(Integer bookId);

    Integer updateBook(BookInfo bookInfo);

    Integer batchDelete(List<Integer> ids);
}
